(function(scope) {
	var KeyWordSet = Base.extend({
		constructor : function(config) {
			this.version = "1.0";
			this.param ={};
			this.action_type="";
		},
		save:function(){
			var me =this;
			if(!commonJS.validate())
				return;
			var params = commonJS.getInputDomain();
			jQuery.extend(this.param,params);
			if(!this.action_type){
				pop({"text":"请选择操作的记录!"});
				return;
			}
			if(this.action_type =='A'){
				Service.asExcute('IKeyWordConfig','addKeyWordConfig',  [this.param], function (replay){
		              me.queryKeyWordList();
		              if(replay == null || replay ==''){
		            	  pop({"text":"新增过虑条件失败！"});
		              }else{
		            	  pop({"text":replay}); 
		              }
		             
				});
			} else if(this.action_type =='M'){
				Service.asExcute('IKeyWordConfig','modifyKeyWordConfig',  [this.param], function (replay){
		              me.queryKeyWordList();
		              if(replay == null || replay ==''){
		            	  pop({"text":"新增过虑条件失败！"});
		              }else{
		            	  pop({"text":replay}); 
		              }
		             
				});
			}
			
		},
		setDisabled:function(type){//设置为不可编辑
			if(type=="0"){
				$("[fieldType='db']").attr("disabled",true);
			}
			else
				$("[fieldType='db']").removeAttr("disabled");
		},
		retValues:function(){//重置所有值
			$("[fieldType='db'][type!='radio']").val("");
		},
		dealAcct:function(){
			var me =this;
			//处理TODO
						
			if(this.action_type == 'D'){

				var filter_id = $("#filter_id").val();
				Service.asExcute('IKeyWordConfig','deleteKeyWordConfig',  [{filter_id:filter_id}], function (replay){
					  me.queryKeyWordList();
		              pop({"text":replay});
				})
			}
			
		},
		getSelTr:function(){
			return $("[ name='acct_radio']:checked").closest("tr");
		},
	    STATIC_CONFIG_DATA : {
				"H":"高",
				"M" : "中",
				"L" : "低",
				"":""
				
			},
		queryKeyWordList:function(){ //查询关联帐户
			var me =this;
			var tbodyJq = $("#keyword_list");
			tbodyJq.empty();
			
			//TODO查询列表，将值赋值到文本框中区保存
			Service.asExcute('IKeyWordConfig','qryAllKeyWordConfig' , [{keyword:'key'}], function (replay){
	              var list = replay
	  			if(list.length >0){
	  			  for(var i=0;i<list.length;i++)
		  			{
	  				    var map = list[i];
		  				var className = i%2 ==0?"":"gray";
		  				var trJq =$('<tr class='+className+' style="cursor:hand;"> <td > <input type="radio" name="acct_radio" ></td>'+
		  						'<td class="strong">'+(i+1)+'</td> <td>'+map["filter_name"]+'</td><td>'+map["keyword_text"]+'</td><td>'+ me.STATIC_CONFIG_DATA[map['alarm_level']]+'</td></tr>').bind("click",
		  				function(){
		  					if (keyWordSet.action_type =='A' || keyWordSet.action_type =='M'){
		  						if(confirm("是否取消当前操作？")){
		  							$('#cancel_keyword_btn').trigger("click");
		  						 }else{
		  							 return ; 
		  						 }
		  					}
		  					$(this).find(":radio").attr("checked",true);
		  					var map = $(this).data("keyword_data");
		  					$("#filter_name").val(map["filter_name"]);
		  					$("#filter_id").val(map["filter_id"]);
		  					
		  					$("#rule_type").val(map["rule_type"]);
		  					
		  					$("#keyword_text").val(map["keyword_text"]);
		  					$("#alarm_level").val(map["alarm_level"]);
		  				
		  					//TODO 点击赋值到文本框
		  					
		  				}).data("keyword_data",map);
		  				tbodyJq.append(trJq);
		  			}
	  			  	tbodyJq.find("tr:eq(0)").trigger("click");
	  			  
	  				
	  			}
	              
	            
			})
			
		}
	})
	window.keyWordSet = new KeyWordSet();
}(window));
$(function() {
	keyWordSet.setDisabled("0");
	keyWordSet.queryKeyWordList();
	addEventById("add_keyword_btn",null,"click",function(){
		keyWordSet.action_type ="A";
		keyWordSet.setDisabled("1");
		keyWordSet.retValues();
	});
	addEventById("mod_keyword_btn",null,"click",function(){
		keyWordSet.action_type ="M";
		keyWordSet.setDisabled("1");
		keyWordSet.dealAcct();
	});
	addEventById("del_keyword_btn",null,"click",function(){
		keyWordSet.action_type ="D";
		
		var rule_type = $("#rule_type").val();
		if(rule_type != 'K'){
			alert('不能删除该数据！');
			return ;
		}
		 if(confirm("是否确定删除过虑信息！")){
			 keyWordSet.dealAcct();
		 }
	});
	addEventById("cancel_keyword_btn",null,"click",function(){
		keyWordSet.action_type ="";
		keyWordSet.setDisabled("0");
	});
	
	downLoadSelectDatas();
	
})